package com.SeleniumTestsFirefox;

import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class CancelReservationTestCases extends SeleneseTestBase {
	
	@Before
	public void setUp() throws Exception {
		WebDriver driver = new FirefoxDriver();
		String baseUrl = "http://localhost:8080/Website/";
		selenium = new WebDriverBackedSelenium(driver, baseUrl);
	}
	
	// Created by Steven Chow
	// Scenario 1: Reservation Successfully Uncancelled
	@Test
	public void testCancelReservation() throws Exception {
		// Go to website
		selenium.open("");
		// Login
		selenium.click("css=div.tile.bg-color-red > div.tile-content.icon > img");
		selenium.waitForPageToLoad("30000");
		selenium.type("name=username", "User4");
		selenium.type("name=password", "pass4");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		assertEquals("Customer Portal", selenium.getTitle());
		// Click on view reservation
		selenium.click("css=div.tile.bg-color-blue > div.tile-content.icon > img");
		selenium.waitForPageToLoad("30000");
		// Check if we are on the right page
		assertEquals("Reservation List", selenium.getTitle());
		// Check if our reservation is there
		assertEquals(
				"200.0",
				selenium.getText("//html/body/div/div[2]/div/div/div/div/form/table/tbody/tr/td[6]"));
		selenium.click("name=r1");
		selenium.click("name=remove");
		selenium.waitForPageToLoad("30000");
		// Check to see if the Reservation is Cancelled
		assertTrue(selenium.isTextPresent("200 points have been refunded"));
		assertTrue(selenium.isTextPresent("Reservation ID"));
		selenium.click("//a[contains(@href, '/Website/ViewResListURL?username=User4')]");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium
				.isTextPresent("No Data To Display. No Reservations are made."));
	}


	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
